
function Get-CMCollection
{
<#
.Synopsis
    Returns a collection, or all instances of a collection.
.Description
    Returns a collection, or all instances of a collection.
.Parameter ComputerName 
    ConfigMgr Site Server Name
.Parameter CollectionID
    Enter CollectionID 
.Parameter Filter
    Enter Filter       
.Parameter Credential 
    Enter Alternate Credentials if required
.Example
    Get-CMCollection
.Example
    Get-CMCollection MYTESTLABServer
        Returns all instances of the SMS_Collection Class on MYTESTLABServer
.Example
    Get-CMCollection MYTESTLABServer LAB00012 
        Returns Collection LAB00012 on MYTESTLABServer
.Example
    Get-CMCollection MYTESTLABServer LAB00012 get-credential
        Prompts for credentials
.Example
    Get-CMCollection MYTESTLABServer LAB00012 $Cred
        uses credentials in $Cred
.Outputs
    Returns either an instance, or multiple instances from the SMS_Collection Class
.Link
    http://msdn.microsoft.com/en-us/library/cc145320.aspx
.Notes
 NAME:      Get-CMCollection
 AUTHOR:    Greg Ramsey
 LASTEDIT:  08/07/2009 00:39:05
#Requires -Version 2.0
#>

[CmdletBinding(
    SupportsShouldProcess=$False,
    SupportsTransactions=$False, 
    ConfirmImpact="None",
    DefaultParameterSetName="")]
param(
[Parameter(Position=0)]
[String]$ComputerName="." ,

[Parameter(Position=1)]
[String]$CollectionID ,

[Parameter(Position=2)]
[String]$Filter=$Null ,

[Parameter(Position=3)]
$Credential
)

Begin
{
}#Begin

Process
{
    get-cmobject -class sms_collection -ComputerName $ComputerName -Filter $Filter -Credential $Credential | ? {$_.CollectionID -like ($CollectionID + "*")}
}#Process

End
{
}#End
}


function Get-CMComputer
{
<#
.Synopsis
    Returns computer objects from SMS_R_SYSTEM.
.Description
    Returns computer objects from SMS_R_SYSTEM.
.Parameter ComputerName 
    ConfigMgr Site Server Name
.Parameter NETBIOSName
    Enter NETBIOSNAME      
.Parameter ResourceID
    Enter ResourceID
.Paramteter ADSiteName
    Enter ADSiteName
.Parameter DomainName
    Enter DomainName
.Parameter SMBIOSGUID
    Enter SMBIOSGUID    
.Parameter Filter
    Enter Filter
.Parameter Credential 
    Enter Alternate Credentials if required
.Example
    Get-CMComputer
.Example
    Get-CMComputer MYTESTLABServer
        Returns all instances of the SMS_R_SYSTEM Class on MYTESTLABServer
.Example
    Get-CMComputer MYTESTLABServer MyTestComputer 
        Returns Computer object MyTestComputer on MYTESTLABServer
.Example
    Get-CMComputer MYTESTLABServer -ADSiteName MyADSite get-credential
        Returns All computer objects in AD Site "MyADSite", and Prompts for credentials
.Example
    Get-CMComputer MYTESTLABServer -Filter "Active=1 AND Obsolete=0"
        Returns All computer objects based on custom filter.
.Example
    Get-CMComputer MYTESTLABServer  $Cred
        uses credentials in $Cred
.Outputs
    Returns either an instance, or multiple instances from the SMS_Collection Class
.Link
    #http://msdn.microsoft.com/en-us/library/cc145320.aspx
.Notes
 NAME:      Get-CMCollection
 AUTHOR:    Greg Ramsey
 LASTEDIT:  03/26/2010 00:39:05
#Requires -Version 2.0
#>

[CmdletBinding(
    SupportsShouldProcess=$False,
    SupportsTransactions=$False, 
    ConfirmImpact="None",
    DefaultParameterSetName="")]
param(
[Parameter(Position=0)]
[String]$ComputerName="." ,

[Parameter(Position=1)]
[String]$NetbiosName="%" ,

[Parameter(Position=2)]
[int32]$ResourceID=$Null ,

[Parameter(Position=3)]
[String]$ADSiteName="%" ,

[Parameter(Position=4)]
[String]$DomainName="%" ,

[Parameter(Position=5)]
[String]$SMBIOSGUID="%" ,

[Parameter(Position=6)]
[String]$Filter=$Null ,

[Parameter(Position=7)]
$Credential
)

Begin
{
}#Begin

Process
{
    if ($ResourceID -eq 0)
    {
        Get-CMObject -Computer $ComputerName -class "SMS_R_System" -Credential $Credential -Filter "NetbiosName LIKE '$NetbiosName' AND ResourceDomainOrWorkgroup LIKE '$DomainName' AND ADSiteName LIKE '$ADSiteName' AND SmBiosGuid LIKE '$SmBiosGuid'"   
    }
    if ($ResourceID -ne 0)
    {
        Get-CMObject -Computer $ComputerName -class "SMS_R_System" -Filter "ResourceID = $ResourceID" -credential $credential
        
    }
}#Process

End
{
}#End
}



function Get-CMUser
{
<#
.Synopsis
    Returns user objects from SMS_R_User.
.Description
    Returns user objects from SMS_R_User.
.Parameter ComputerName 
    ConfigMgr Site Server Name
.Paramteter UserName
    Enter UserName
.Parameter ResourceID
    Enter ConfigMgr ResourceID      
.Parameter Domain
    Enter Domain Name
.Parameter Filter
    Enter Filter
.Parameter Credential 
    Enter Alternate Credentials if required
.Example
    Get-CMUser
        Returns all users from the SMS_R_User Class on the local site server
.Example
    Get-CMUser MYTESTLABServer
        Returns all instances of the SMS_R_User Class on MYTESTLABServer
.Example
    Get-CMUser MYTESTLABServer lab\greg_ramsey 
        Returns USER object lab\greg_ramsey on MYTESTLABServer
.Example
    Get-CMUser MYTESTLABServer get-credential
        Returns All user objects and Prompts for credentials
.Example
    Get-CMUser MYTESTLABServer  $Cred
        uses credentials in $Cred
.Outputs
    Returns either an instance, or multiple instances from the SMS_Collection Class
.Link
    http://msdn.microsoft.com/en-us/library/cc142968.aspx
.Notes
 NAME:      Get-CMUser
 AUTHOR:    Greg Ramsey
 LASTEDIT:  03/26/2010 00:39:05
#Requires -Version 2.0
#>

[CmdletBinding(
    SupportsShouldProcess=$False,
    SupportsTransactions=$False, 
    ConfirmImpact="None",
    DefaultParameterSetName="")]
param(
[Parameter(Position=0)]
[String]$ComputerName="." ,

[Parameter(Position=1)]
[int32]$ResourceID=$Null ,

[Parameter(Position=2)]
[String]$UserName="%" ,

[Parameter(Position=3)]
[String]$DomainName="%", 

[Parameter(Position=7)]
$Credential
)

Begin
{
}#Begin

Process
{
    if ($ResourceID -eq 0)
    {
        Get-CMObject -Computer $ComputerName -class "SMS_R_User" -Credential $Credential -Filter "WindowsNTDomain LIKE '$DomainName' AND UserName LIKE '$UserName'"
    }
    if ($ResourceID -ne 0)
    {
        Get-CMObject -Computer $ComputerName -class "SMS_R_User" -Credential $Credential -Filter "ResourceID = $ResourceID"
    }
}#Process

End
{
}#End
}

function Get-CMUserGroup
{
<#
.Synopsis
    Returns user group objects from SMS_R_UserGroup.
.Description
    Returns user group objects from SMS_R_UserGroup.
.Parameter ComputerName 
    ConfigMgr Site Server Name
.Paramteter UniqueUserGroupName
    Enter Unique User Group Name  
.Parameter ResourceID
    Enter ConfigMgr ResourceID      
.Paramteter UserGroupName
    Enter User Group Name
.Parameter Domain
    Enter Active Directory Domain
.Parameter Filter
    Enter Filter
.Parameter Credential 
    Enter Alternate Credentials if required
.Example
    Get-CMUserGroup
        Returns all users from the SMS_R_UserGroup Class on the local site server
.Example
    Get-CMUserGroup MYTESTLABServer
        Returns all instances of the SMS_R_UserGroup Class on MYTESTLABServer
.Example
    Get-CMUserGroup MYTESTLABServer "lab\Domain Admins" 
        Returns USER Group object "lab\Domain Admins" (using property "UniqueUserGroupname" Property) on MYTESTLABServer
.Example
    Get-CMUserGroup MYTESTLABServer get-credential
        Returns All user group objects and Prompts for credentials
.Example
    Get-CMUserGroup MYTESTLABServer  $Cred
        uses credentials in $Cred
.Outputs
    Returns either an instance, or multiple instances from the SMS_Collection Class
.Link
    http://msdn.microsoft.com/en-us/library/cc146332.aspx
.Notes
 NAME:      Get-CMUser
 AUTHOR:    Greg Ramsey
 LASTEDIT:  03/26/2010 00:39:05
#Requires -Version 2.0
#>

[CmdletBinding(
    SupportsShouldProcess=$False,
    SupportsTransactions=$False, 
    ConfirmImpact="None",
    DefaultParameterSetName="")]
param(
[Parameter(Position=0)]
[String]$ComputerName="." ,

[Parameter(Position=1)]
[String]$UniqueUserGroupName="%" ,

[Parameter(Position=2)]
[int32]$ResourceID=$Null ,

[Parameter(Position=3)]
[String]$UserGroupName="%" ,

[Parameter(Position=4)]
[String]$DomainName="%", 

[Parameter(Position=5)]
[String]$Filter="%", 

[Parameter(Position=7)]
$Credential
)

Begin
{
}#Begin

Process
{
    if ($ResourceID -eq 0)
    {
        Get-CMObject -Computer $ComputerName -class "SMS_R_UserGroup" -Credential $Credential -Filter "ActiveDirectoryDomain LIKE '$DomainName' AND UniqueUserGroupName LIKE '$UniqueUserGroupName' AND UserGroupName LIKE '$UserGroupName'"
    }
    if ($ResourceID -ne 0)
    {
        Get-CMObject -Computer $ComputerName -class "SMS_R_UserGroup" -Credential $Credential -Filter "ResourceID = $ResourceID"
    }
}#Process

End
{
}#End
}

function Get-CMCollectionMembers
{
<#
.Synopsis
    Returns all Collection Members for a collection.
.Description
    Returns all Collection Members for a collection.
.Parameter SiteServerName 
    ConfigMgr Site Server Name
.Parameter CollectionID
    Enter CollectionID    
.Parameter Credential 
    Enter Alternate Credentials if required
.Example
    Get-CMCollectionMembers LAB00012
        Returns all Collection Members of the CollectionID=LAB00012 on the local site server.
.Example
    Get-CMCollectionMembers MYTESTLABServer LAB00012 
        Returns all Collection Members of the CollectionID=LAB00012 on the site server named MYTESTLABServer.
.Example
    Get-CMCollectionMembers MYTESTLABServer LAB00012 get-credential
        Prompts for credentials
.Example
    Get-CMCollectionMembers MYTESTLABServer LAB00012 $Cred
        uses credentials in $Cred
.Outputs
    Returns either an instance, or multiple instances from the SMS_Package Class
.Link
    http://msdn.microsoft.com/en-us/library/cc145603.aspx
.Notes
 NAME:      Get-CMCollectionMembers
 AUTHOR:    Greg Ramsey
 LASTEDIT:  08/07/2009 00:39:05
#Requires -Version 2.0
#>

[CmdletBinding(
    SupportsShouldProcess=$False,
    SupportsTransactions=$False, 
    ConfirmImpact="None",
    DefaultParameterSetName="")]
param(
[Parameter(Position=0)]
[String]$ComputerName="." ,

[Parameter(Mandatory=$true,Position=1)]
[String]$CollectionID ,

[Parameter(Position=2)]
[String]$Filter ,

[Parameter(Position=3)]
$Credential
)

Begin
{
}#Begin

Process
{
    get-cmobject -class ("SMS_CM_RES_COLL_" + $CollectionID) -ComputerName $ComputerName -Filter $Filter -Credential $Credential
}#Process

End
{
}#End
}



function Get-CMCollectionRules
{
<#
.Synopsis
    Returns all collection rules for a collection.
.Description
    Returns all collection rules for a collection.
.Parameter SiteServerName 
    ConfigMgr Site Server Name
.Parameter CollectionID
    Enter CollectionID    
.Example
    Get-CMCollectionRules MYTESTLABServer LAB00012 
        Returns collection rules for collectionid=LAB00012 on MYTESTLABServer
.Outputs
    Returns all collection rules for a collection.
.Link
    #http://msdn.microsoft.com/en-us/library/cc144959.aspx
.Notes
 NAME:      Get-CMCollectionRules
 AUTHOR:    Greg Ramsey
 LASTEDIT:  03/27/2010 00:39:05
#Requires -Version 2.0
#>

[CmdletBinding(
    SupportsShouldProcess=$False,
    SupportsTransactions=$False, 
    ConfirmImpact="None",
    DefaultParameterSetName="")]
param(
[Parameter(Position=0)]
[String]$ComputerName="." ,

[Parameter(Position=1)]
[String]$CollectionID ,

[Parameter(Position=2)]
[String]$Filter ,

[Parameter(Position=3)]
$Credential
)

Begin
{
}#Begin

Process
{
    if ($Credential)
    {
        write-host "`$Credential cannot be used with this function, must run as current user :( "
    }
    else
    {
        if ($filter -eq "")
        {
        #(get-cmcollection -ComputerName $ComputerName -filter "CollectionID='$CollectionID'")
        
            ([wmi](get-cmcollection -ComputerName $ComputerName -filter "CollectionID='$CollectionID'").__Path).CollectionRules
        }
        else
        {
            
            ([wmi](get-cmcollection -ComputerName $ComputerName -filter $Filter).__Path).CollectionRules
        }
    }
    
    
}#Process

End
{
}#End
}

